package com.manager.common.init;

import com.manager.common.job.*;
import com.manager.common.tcp.client.TcpClient;
import com.manager.common.tcp.watch.TcpClientWatchDog;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Component
public class SpringBootInit implements ApplicationRunner {

    @Value("${tcp.server.port}")
    private Integer tcpServerPort;

    @Value("${tcp.server.ip}")
    private String tcpServerIp;

    @Value("${web.receipt.url}")
    private String receiptUrl;

    @Value("${web.exception.containers.url}")
    private String exceptionContainerUrl;

    @Value("${web.tcp.file.report.url}")
    private String tcpFileReportUrl;

    @Value("${linux.ssh.ip}")
    private String linuxSshIp;

    @Value("${linux.ssh.port}")
    private int linuxSshPort;

    @Value("${linux.ssh.user.name}")
    private String linuxSshUserName;

    @Value("${linux.ssh.password}")
    private String linuxSshPassword;


    @Override
    public void run(ApplicationArguments args) throws Exception {

        ReceiptThread receiptThread = new ReceiptThread(receiptUrl,tcpFileReportUrl,exceptionContainerUrl);
        receiptThread.start();

        //String ip, Integer port, String password, String userName
        DisposeReportCommandThread disposeReportCommandThread = new DisposeReportCommandThread(linuxSshIp,linuxSshPort,linuxSshPassword,linuxSshUserName);
        disposeReportCommandThread.start();

        TcpClient tcpClient = TcpClient.getInstance();
        tcpClient.connect(tcpServerIp, tcpServerPort);

        TcpClientWatchDog  tcpClientWatchDog = new TcpClientWatchDog(tcpServerIp,tcpServerPort);
        tcpClientWatchDog.start();

    }
}

